<template>
  <base-layout>
    <template #searchPanel>
      <search-panel
        @search="search"
        @insert="addCarModel"
        :showAddButton="true"
        :addPer="authConfig.add"
        :selectPer="authConfig.query"
      >
        <CarModel v-model="carModels" ref="carModel" placeholder="车型组件" />
        <el-input
          v-model="form.modelName"
          clearable
          placeholder="车型名称"
          style="width: 200px"
        />
      </search-panel>
    </template>

    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="修改"
            style="margin-left: 20px; cursor: pointer"
            v-permission="authConfig.edit"
            @click="handleDataEdit(row)"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"
            v-permission="authConfig.del"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
      <!--工具条-->
    </template>
  </base-layout>
</template>

<script>
import {
  dataList,
  dicts,
  details,
  addData,
  updateData,
  deleteData
} from '@/api/after-sale/systemManage/carModel'
import baseMixin from '@/mixins/base'
import { parseTimeToYMDHMS } from '@/utils'
import { getDict } from '@/utils/index'
export default {
  mixins: [
    baseMixin({
      idName: 'id',
      findData: dataList,
      dataName: ['content', 'totalRecords'],
      addData: addData,
      updateData: updateData,
      deleteData: deleteData,
      isAdd: false,
      findDataById: details,
      idName: 'id',
      format(res) {
        return res.map((data) => {
          data.businessHours = `${data.startTime}-${data.endTime}`
          return data
        })
      },
    }),
  ],
  data() {
    return {
      authConfig: {
        query: 'carModel:page',
        add: 'carModel:create',
        edit: 'carModel:update',
        del: 'carModel:delete',
      },
      dialogVisible: false,
      isAdd: false,
      tableColumnAttributes: [
        // text data select input input  有maxlength属性  如果是select 传入action 函数，则下拉数据改变后会回调这个方法
        // date 宽度为 210  日期为text时宽度为 150
        { name: '首字母', value: 'brandInitial', type: 'text', },
        { name: '品牌图标', value: 'brandLogo', type: 'img', width: '100' },
        { name: '车型展示图', value: 'county', type: 'img', width: '100' },
        { name: '品牌', value: 'brandName', type: 'text', width: '200' },
        { name: '车系', value: 'seriesName', type: 'text', width: '200' },
        { name: '年款', value: 'timeType', type: 'text', width: '200' },
        { name: '级别', value: 'rankValue', type: 'text', width: '100' },
        {
          name: '车型',
          value: 'modelName',
          type: 'text',
          width: '300',
        },
        { name: '指导价格', value: 'guidePrice', type: 'text', width: '100' },
        {
          name: '备注',
          value: 'remark',
          type: 'text',
          width: '100',
        },
        { name: '创建时间', value: 'createTime', type: 'text', width: '150' },
      ],
      dict: {},

      form: {
        cityCode: '', //城市编码
        managerName: '', //店长名称
        status: '', //门店状态
        storeId: '', //门店id
        storeName: '', //门店名称
      },
    }
  },
  async created() {},
  methods: {
    search() {
      this.searchOptions = this.form
      this.currentPage = 1
      this.setTableData()
    },
    //新增
    addCarModel(){
      this.$router.push({ path:'/systemManage/addCarModel' })
    },
    handleDataEdit(row){
      this.$router.push({
        path:'/systemManage/editCarModel',
        query:{
          id: row.id,
        }
      })
    }
  },
}
</script>

<style lang="scss" scoped>
</style>
